<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      >
<head th:replace="fragments/tabhead::headc"></head>

<body>

<th:block layout:fragment="content">
<!-- 销售订单 -->
<div style="margin-top:20px">
  <form class="layui-form" id="searchForm">
  <div class="layui-form-item layui-elem-quote">
     
     <div class="layui-inline">
      <label class="layui-form-label" style="width:100px">公司名称</label>
      <div class="layui-input-inline">
        <select name="companyId">
        	<option value="" selected>请选择公司</option>
        	<option th:each="ec:${actCenterCompanyMap}" th:value="${ec.id}" th:text="${ec.name}"></option>
        </select>
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label" style="width:100px">名称</label>
      <div class="layui-input-inline">
        <input type="text" class="layui-input" placeholder="名称" name="name"/>
      </div>
    </div>
    	
    <div class="layui-inline">
      <div class="layui-input-inline" style="width:60px;">
        <button class="layui-btn" id="searchBtn" type="button" authcode="900220">查询</button>
      </div>
      <div class="layui-input-inline" style="width:60px;">
        <button class="layui-btn" id="addBtn" type="button" authcode="900221">新增</button>
      </div>
    </div>
    
  </div>
 </form>
</div>

<table class="layui-table"  id="tab" lay-filter="tab">
</table>

<script>
var ins,page,trobj,editdialogindex,adddialogindex;
$(function(){ 
	
	layui.use(['table','layer','laypage'], function(){
		var table = layui.table;
		var laypage = layui.laypage;
		ins =table.render({ //其它参数在此省略
		 elem:"#tab",
		 url: '/basic/data/dictionary/type/data',
		 cols:[[
			   //fixed 列将会被固定在左或右，不随滚动条而滚动left right
			  {field:'id',width:60, sort: true,title:'ID',fixed:"left"},
		      {field:'companyName', width:200,title:'公司名称'},
		      {field:'name', width:180,title:'字典类型名称'},
		      {field:'decode', width:180,title:'字典类型编码'},
		      {field:'is_preinstall',width:100,title:'系统预设'},
		      {field:'remark', width:150, title:'备注'},
		      {align:'center',fix:'right',width:250, toolbar:'#toolbar',title:'操作',fixed:"right"}
		 ]]
	    ,page: true //是否显示分页
	    ,limits: [10,20,50]
	    ,limit:10 //每页默认显示的数量
		  //where:{phone:phone}
		 ,method: 'post'
		 ,done:function(res,curr,count){
			 console.log(res);
			 page = curr;
			    //得到当前页码
			 console.log(curr); 
			    //得到数据总量
			 console.log(count);
		 }
		});
		
		table.on("tool(tab)",function(obj){
			var data = obj.data; //获得当前行数据
			var layEvent = obj.event; //获得 lay-event 对应的值
			trobj = obj;
			var tr = obj.tr; //获得当前行 tr 的DOM对象
			if(layEvent=='edit'){
				$.post('/basic/data/dictionary/type/edit', {"companyId":1,"id":data.id}, function(str){
				editdialogindex = layer.open({
					id:"pwdupdateDialog",
									title:"修改",
								    type: 1,
								    area: ['680px', '350px'],
								    content: str,//注意，如果str是object，那么需要字符拼接。
								    zIndex:10
								  });
								});
			
			//删除
			}else if(layEvent=='del'){
				var confirmindex = layer.confirm('您确定删除该记录吗？', {
					  btn: ['确定','取消'] //按钮
					}, function(){
						$.post("/basic/data/dictionary/type/del_execute?id="+data.id,function(data){
							if(data.code==200){
								trobj.del();
								layer.close(confirmindex)
							}else{
								layer.msg(data.message);
							}
						});
					}, function(){
					  	
					});
			}else if(layEvent=="detail"){
				$.post('/basic/data/dictionary/type/detail', {"id":data.id}, function(str){
			          editdialogindex = layer.open({
			        	  id:"pwdupdateDialog",
			            title:"详情",
			              type: 1,
			              zIndex:10,
			              area: ['800px', '500px'],
			              content: str //注意，如果str是object，那么需要字符拼接。
			            });
			          });
			}else if(layEvent=="set"){
				menuOpen("/basic/data/dictionary/value/index?typeId=" + data.id, "数据字典设置(" + data.name + ")");
			}
		});
		
		
		//查询按钮点击
		$("#searchBtn").click(function(){
			var table = layui.table;
		    ins.reload({url: '/basic/data/dictionary/type/data',where:$("#searchForm").serializeJson()})
		});
		//增加按钮点击
		$("#addBtn").click(function(){
			$.post('/basic/data/dictionary/type/edit', {"companyId":1,"id":""}, function(str){
				adddialogindex = layer.open({
					id:"pwdupdateDialog",
									title:"新增",
								    type: 1,
								    area: ['680px', '350px'],
								    content: str,//注意，如果str是object，那么需要字符拼接。
								    zIndex:10
								  });
								});
		})
		
	})
	
	layui.use("laydate",function(){
		var laydate = layui.laydate;
		laydate.render({
			  elem: '#startDate' //指定元素
			});
		laydate.render({
			  elem: '#endDate' //指定元素
			});
	});
}); 
function reloadData(){
	$(".layui-laypage-btn")[0].click();
	
}
</script>
<script type="text/html" id="toolbar">
		<a class="layui-btn layui-btn-mini" lay-event="edit" authcode="900223">修改</a>
		<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del" authcode="900222">删除</a>
		<a class="layui-btn layui-btn-mini" lay-event="set" authcode="900224">设置</a>
</script>
<!--<div th:replace="department/model::modelDiv"></div>-->
</th:block>
</body>
</html>